const { Category } = require('../../../model/category');
const { Article } = require('../../../model/article');

module.exports = async (req, res) => {
	let list = []
  categories = await Category.find()
  categories.forEach(async (item, index) => {
	const articles = await Article.find({category: item._id})
	list.push({value: articles.length, name: item.name})
	if (index === categories.length - 1) {
		res.json({
		    data: list
		})
	}
  })
  // res.json({
  //     data: list
  // })
}